﻿Imports System.Windows.Forms

Public Class UnInstal


    '// --------------------------------------------------------------------- '
    Private Sub RecDelFiles(ByVal strPath As String)
        Dim oDir As New System.IO.DirectoryInfo(strPath)
        Dim oSubDir() As System.IO.DirectoryInfo
        Dim oFiles() As System.IO.FileInfo
        Dim i As Int32

        oFiles = oDir.GetFiles
        oSubDir = oDir.GetDirectories()
        For i = 0 To oFiles.Length - 1
            Try
                System.IO.File.Delete(oFiles(i).FullName)
            Catch ex As Exception
                Debug.Print("Failed to delete " & oFiles(i).FullName)
            End Try
        Next

        For i = 0 To oSubDir.Length - 1
            Call RecDelFiles(oSubDir(i).FullName)
        Next
    End Sub
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    Private Sub OK_Button_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles OK_Button.Click

        Dim myCuiFile As String

        Try
            myCuiFile = CApp.sAppPath & "Misc\UI.cui"
            '// delete registry keys
            CApp.UnregisterMyApp()

            '// remove custom components
            CApp.ads_queueexpr("(command " & CApp.QUOTE & "CUIUNLOAD" & _
                               CApp.QUOTE & " " & CApp.QUOTE & _
                               myCuiFile.Replace("\"c, "/"c) & _
                               CApp.QUOTE & ")")

            '// delete files in instalation folder
            RecDelFiles(CApp.sAppPath)


            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.Close()
        Catch ex As Exception
            CMain.DebugException(ex)
        End Try
        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub Cancel_Button_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles Cancel_Button.Click

        GC.Collect()
        GC.WaitForPendingFinalizers()
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub UnInstal_Load( _
        ByVal sender As System.Object,  _
        ByVal e As System.EventArgs) _
        Handles MyBase.Load

        Me.Text = CMain._T(TX.UNINSTFSK)
        Me.OK_Button.Text = CMain._T(TX.UPDATE)
        Me.Cancel_Button.Text = CMain._T(TX.CANCEL)
        Me.TX_Info.Text = String.Format(CMain._T(TX.UNINSTMSG), CApp.sAppPath)

    End Sub
    '// ===================================================================== '

End Class
